﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Projet
{
    /// <summary>
    /// Interaction logic for AddUser.xaml
    /// </summary>
    public partial class AddUser : Window
    {
        
        
        Bdd bdd = new Bdd();
        public AddUser()
        {
            
            InitializeComponent();
        }
  
        public void Initialize(CurrentUser currentUser) 
        {
            if (currentUser.privilege == 1)
            {
                manageLabelCursus.ItemsSource = bdd.getCursus();
                CampusBox.ItemsSource = bdd.GetCampus();
            }
            else if (currentUser.privilege == 2)
            {
                manageLabelCursus.ItemsSource = bdd.GetCursusFromCampus(currentUser.campus);
                CampusBox.ItemsSource = bdd.GetCampus();
                CampusBox.SelectedItem = currentUser.campus;
                CampusBox.IsEnabled = false;
            }
        }

        private void addThis_Click(object sender, RoutedEventArgs e)
        {
           if (nameBox.Text != "" && firstnameBox.Text != "" && passwdbox.Text.Length >= 10)
            {
                bdd.AddUser(nameBox.Text, firstnameBox.Text, CampusBox.SelectedItem.ToString(), PrivilegesBox.SelectedIndex + 1, passwdbox.Text, manageLabelCursus.SelectedItem.ToString(), manageLabelClasses.SelectedIndex);
                MessageBox.Show("User has been created");
                this.Close();
            }
            else { MessageBox.Show("Error: All fields must be filled and password must have a minimum of 10 characters"); }
        }

        private void CampusBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }     
    }
 }
